<!DOCTYPE html>


<html lang="zn-CH">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="What I can do is to Do My Personal Best!" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    sql常用语法合集 |  小熊的博客
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="http://www.cdn.adingxiong.com/b5363a06dc744d79a94021492bcefe27" />
  
  
<link rel="stylesheet" href="/blog/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/blog/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/blog/atom.xml" title="小熊的博客" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content on">
      <section class="outer">
  <article id="post-sql常用语法合集" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  sql常用语法合集
</h1>
 

    </header>
    

    
    <div class="article-meta">
      <a href="/blog/2020/04/18/sql%E5%B8%B8%E7%94%A8%E8%AF%AD%E6%B3%95%E5%90%88%E9%9B%86/" class="article-date">
  <time datetime="2020-04-18T07:25:41.000Z" itemprop="datePublished">2020-04-18</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/blog/categories/SQL/">SQL</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">848</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">4 min</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      
      

      
      <h5 id="1-case-when-的用法sum-case-when-x-x-then-1-else-0"><a href="#1-case-when-的用法sum-case-when-x-x-then-1-else-0" class="headerlink" title="1. case when 的用法sum(case when x = x then 1 else 0)"></a>1. case when 的用法<code>sum(case when x = x then 1 else 0)</code></h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select sum (case when isintroduce &#x3D; &#39;0&#39; then 1 else 0 end) noreg,sum (case when isintroduce &#x3D;&#39;1&#39; then 1 else 0 end )reg from lae05 where 1&#x3D;1</span><br></pre></td></tr></table></figure>

<h5 id="2-时间格式转换-date-format-field-39-Y-m-d-39"><a href="#2-时间格式转换-date-format-field-39-Y-m-d-39" class="headerlink" title="2. 时间格式转换 date_format(field,&#39;%Y-%m-%d&#39;)"></a>2. 时间格式转换 <code>date_format(field,&#39;%Y-%m-%d&#39;)</code></h5><p>后面的格式可以自定义修改比如<code>%m-%d</code> 或者<code>%m.%d</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">select count(1) as total ,</span><br><span class="line">    sun(case when status &#x3D;&#39;end&#39; then 1 else 0 ) as finish</span><br><span class="line">from </span><br><span class="line">    fault where date_format(create_time,&#39;%Y-%m-%d&#39;) &gt;&#x3D;&#39;2020-10-01&#39; </span><br><span class="line">    and  date_format(create_time,&#39;%Y-%m-%d&#39;) &lt; &#39;2020-12-12&#39;</span><br></pre></td></tr></table></figure>
<h5 id="3-百分比结果计算-round-a-b-2"><a href="#3-百分比结果计算-round-a-b-2" class="headerlink" title="3. 百分比结果计算  round((a/b),2)"></a>3. 百分比结果计算  <code>round((a/b),2)</code></h5><p><code>round</code>函数,第一个参数是对结果进行计算,第二位是保留的小数点 </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">select </span><br><span class="line">   *,round((a.finish&#x2F;a.total),2)*100 as percent</span><br><span class="line">from (</span><br><span class="line">    select </span><br><span class="line">        count(1) as total,</span><br><span class="line">        sum(case when status &#x3D;1 then 1 else 0) as finish </span><br><span class="line">    from fault where sorce between 12 and 50</span><br><span class="line">) as a</span><br></pre></td></tr></table></figure>

<h5 id="4-分组-聚合-group-by"><a href="#4-分组-聚合-group-by" class="headerlink" title="4. 分组(聚合)group by"></a>4. 分组(聚合)<code>group by</code></h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">select </span><br><span class="line">    name,age,course</span><br><span class="line">from job group by course order b by userid</span><br></pre></td></tr></table></figure>


<h5 id="5-对两张表相同字段求和并计算百分比"><a href="#5-对两张表相同字段求和并计算百分比" class="headerlink" title="5. 对两张表相同字段求和并计算百分比"></a>5. 对两张表相同字段求和并计算百分比</h5><p>两个表拥有相同的字段</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 单独一张表求和</span></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">sum</span>(<span class="keyword">case</span> <span class="keyword">when</span> <span class="keyword">status</span> =<span class="string">'end'</span>) <span class="keyword">as</span> <span class="keyword">end</span> ,<span class="keyword">count</span>(<span class="number">1</span>) <span class="keyword">as</span> total <span class="keyword">from</span> fault;</span><br><span class="line"><span class="keyword">select</span> <span class="keyword">sum</span>(<span class="keyword">case</span> <span class="keyword">when</span> <span class="keyword">status</span> =<span class="string">'end'</span>) <span class="keyword">as</span> <span class="keyword">end</span> ,<span class="keyword">count</span>(<span class="number">1</span>) <span class="keyword">as</span> total <span class="keyword">from</span> <span class="keyword">repair</span>;</span><br><span class="line"><span class="comment">-- 两张表结果求和并计算百分比</span></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">sum</span>(a.end) <span class="keyword">end</span>,<span class="keyword">sum</span>(a.total) total,<span class="keyword">round</span>((<span class="keyword">end</span>/total),<span class="number">2</span>) <span class="keyword">as</span> <span class="keyword">percent</span> <span class="keyword">from</span> (</span><br><span class="line"><span class="keyword">select</span> <span class="keyword">sum</span>(<span class="keyword">case</span> <span class="keyword">when</span> <span class="keyword">status</span> =<span class="string">'end'</span> <span class="keyword">then</span> <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> <span class="keyword">end</span>) <span class="keyword">end</span>,<span class="keyword">count</span>(<span class="number">1</span>) <span class="keyword">as</span> total <span class="keyword">from</span> fault</span><br><span class="line"><span class="keyword">union</span> <span class="keyword">all</span> </span><br><span class="line"><span class="keyword">select</span> <span class="keyword">sum</span>(<span class="keyword">case</span> <span class="keyword">when</span> <span class="keyword">status</span> =<span class="string">'end'</span> <span class="keyword">then</span> <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> <span class="keyword">end</span>) <span class="keyword">end</span>,<span class="keyword">count</span>(<span class="number">1</span>) <span class="keyword">as</span> total <span class="keyword">from</span> <span class="keyword">repair</span>)a</span><br></pre></td></tr></table></figure>

<h5 id="6-两张表相同字段求和并分组计算"><a href="#6-两张表相同字段求和并分组计算" class="headerlink" title="6. 两张表相同字段求和并分组计算"></a>6. 两张表相同字段求和并分组计算</h5><p>思路,先将字段相同的全连接查询,然后根据指定的条件进行分组  </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line">SELECT</span><br><span class="line">	*, round((b. END &#x2F; b.total), 2) * 100 AS percentage</span><br><span class="line">FROM</span><br><span class="line">	(</span><br><span class="line">		SELECT</span><br><span class="line">			date_format(a.create_date, &#39;%m-%d&#39;) AS date,</span><br><span class="line">			sum(</span><br><span class="line">				CASE</span><br><span class="line">				WHEN a. STATUS &#x3D; &#39;end&#39; THEN</span><br><span class="line">					1</span><br><span class="line">				ELSE</span><br><span class="line">					0</span><br><span class="line">				END</span><br><span class="line">			) AS</span><br><span class="line">		END,</span><br><span class="line">		count(1) AS total,</span><br><span class="line">		processing_person_id AS processId</span><br><span class="line">	FROM</span><br><span class="line">		(</span><br><span class="line">			SELECT</span><br><span class="line">				create_date,</span><br><span class="line">				STATUS,</span><br><span class="line">				process_id,</span><br><span class="line">				processing_person_id</span><br><span class="line">			FROM</span><br><span class="line">				fault</span><br><span class="line">			UNION ALL</span><br><span class="line">				SELECT</span><br><span class="line">					create_date,</span><br><span class="line">					STATUS,</span><br><span class="line">					process_id,</span><br><span class="line">					processing_person_id</span><br><span class="line">				FROM</span><br><span class="line">					REPAIR</span><br><span class="line">		) a</span><br><span class="line">	WHERE</span><br><span class="line">		date_format(a.create_date, &#39;%Y-%m-%d&#39;) &gt;&#x3D; &#39;2020-03-01&#39;</span><br><span class="line">	AND date_format(a.create_date, &#39;%Y-%m-%d&#39;) &gt;&#x3D; &#39;2020-03-01&#39;</span><br><span class="line">	GROUP BY</span><br><span class="line">		processing_person_id</span><br><span class="line">	ORDER BY</span><br><span class="line">		processing_person_id</span><br><span class="line">	) b</span><br><span class="line"></span><br><span class="line">-- 结果如下所示</span><br><span class="line">date | end| total| percentage</span><br><span class="line">--------------------------</span><br><span class="line">03-22	7	12		58.00</span><br><span class="line">--------------------------</span><br><span class="line">04-09	0	3	3	0.00</span><br><span class="line">--------------------------</span><br><span class="line">04-09	0	1	4	0.00</span><br><span class="line">--------------------------</span><br><span class="line">03-05	0	6	18	0.00</span><br><span class="line">--------------------------</span><br><span class="line">04-01	0	2	22	0.00</span><br><span class="line">--------------------------</span><br></pre></td></tr></table></figure>

<h5 id="7-CAST函数说明以及使用"><a href="#7-CAST函数说明以及使用" class="headerlink" title="7. CAST函数说明以及使用"></a>7. <code>CAST</code>函数说明以及使用</h5><p><code>cast</code>函数的作用是实现数据类型的转换,函数包括两个参数,元数据和新的数据类型<br>示例:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 将整型类型转换成字符串</span></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">cast</span>(<span class="number">9</span>, <span class="keyword">as</span> <span class="built_in">CHAR</span>);</span><br><span class="line"><span class="comment">-- 将字符串转换成时间格式 </span></span><br><span class="line">selec case(NOW() as DATE);</span><br></pre></td></tr></table></figure>

<p>需要注意的事 <code>cast</code>函数对转换的类型也是有限值的</p>
<ul>
<li>二进制，同带binary前缀的效果 : BINARY    </li>
<li>字符型，可带参数 : CHAR()     </li>
<li>日期 : DATE     </li>
<li>时间: TIME     </li>
<li>日期时间型 : DATETIME     </li>
<li>浮点数 : DECIMAL      </li>
<li>整数 : SIGNED     </li>
<li>无符号整数 : UNSIGNED </li>
</ul>
<h5 id="8-ConCAT函数的使用"><a href="#8-ConCAT函数的使用" class="headerlink" title="8. ConCAT函数的使用"></a>8. <code>ConCAT</code>函数的使用</h5><p><code>concat</code>函数的作用是对结果集进行字符拼接,一般出现比较多的事在百分比计算中</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 计算小明的所有成绩及格率  </span></span><br><span class="line"><span class="keyword">select</span> *,<span class="keyword">concat</span>(<span class="keyword">cast</span>(<span class="keyword">round</span>((a.pass/a.count),<span class="number">2</span>) <span class="keyword">as</span> <span class="built_in">CHAR</span>),<span class="string">'%'</span>) <span class="keyword">as</span> percentag <span class="keyword">from</span> (</span><br><span class="line"><span class="keyword">select</span> </span><br><span class="line">	<span class="keyword">count</span>(<span class="number">1</span>) <span class="keyword">as</span> <span class="keyword">count</span>,</span><br><span class="line">	<span class="keyword">sum</span>(<span class="keyword">case</span> <span class="keyword">when</span> grade &gt; <span class="number">60</span> <span class="keyword">then</span> <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> <span class="keyword">end</span>) <span class="keyword">as</span> pass	</span><br><span class="line"><span class="keyword">from</span> <span class="keyword">result</span>) a</span><br></pre></td></tr></table></figure>

<h5 id="9-讲多个表的结果集，组装新的字段以一条数据显示"><a href="#9-讲多个表的结果集，组装新的字段以一条数据显示" class="headerlink" title="9. 讲多个表的结果集，组装新的字段以一条数据显示"></a>9. 讲多个表的结果集，组装新的字段以一条数据显示</h5><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> </span><br><span class="line">	a1.count sw,</span><br><span class="line">	a2.count org,</span><br><span class="line">	a3.count <span class="keyword">project</span>  </span><br><span class="line"><span class="keyword">from</span> (</span><br><span class="line">	<span class="keyword">SELECT</span> </span><br><span class="line">		<span class="keyword">count</span>(*) </span><br><span class="line">	<span class="keyword">from</span> </span><br><span class="line">		lap21</span><br><span class="line">	<span class="keyword">where</span> </span><br><span class="line">		areaid &gt;= <span class="string">'areaid'</span> <span class="keyword">and</span> </span><br><span class="line">		areaid &lt; <span class="string">'maxAreaid'</span>) a1,</span><br><span class="line">	(</span><br><span class="line">	<span class="keyword">select</span> </span><br><span class="line">		<span class="keyword">count</span>(*) </span><br><span class="line">	<span class="keyword">from</span> </span><br><span class="line">		lae01 </span><br><span class="line">	<span class="keyword">where</span> </span><br><span class="line">		areaid &gt;= <span class="string">' areaid '</span> <span class="keyword">and</span> </span><br><span class="line">		areaid &lt; <span class="string">' maxAreaid '</span>) a2,</span><br><span class="line">	(</span><br><span class="line">	<span class="keyword">SELECT</span> </span><br><span class="line">		<span class="keyword">count</span>(<span class="number">1</span>) </span><br><span class="line">	<span class="keyword">from</span> </span><br><span class="line">		lax03 </span><br><span class="line">	<span class="keyword">where</span> </span><br><span class="line">		areaid &gt;= <span class="string">' areaid '</span> <span class="keyword">and</span> </span><br><span class="line">		areaid &lt; <span class="string">'maxAreaid '</span>) a3;</span><br></pre></td></tr></table></figure>

      
      <!-- reward -->
      
      <div id="reward-btn">
        Donate
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>Copyright： </strong>
              Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://bodboy.gitee.io/blog/2020/04/18/sql%E5%B8%B8%E7%94%A8%E8%AF%AD%E6%B3%95%E5%90%88%E9%9B%86/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/SQL/" rel="tag">SQL</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/blog/2020/04/18/IDEA%E7%9B%B8%E5%85%B3%E5%B8%B8%E7%94%A8%E9%85%8D%E7%BD%AE%E8%AF%B4%E6%98%8E/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            IDEA相关常用配置说明
          
        </div>
      </a>
    
    
      <a href="/blog/2020/04/18/%E9%9D%A2%E8%AF%95%E9%A2%98%E5%8F%8D%E9%A6%88/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">面试记录，面试反馈</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'uW8QYGvvhWmNWdiwpznJ0GVa-gzGzoHsz',
        app_key: 'LrJhMzx9qEwcMV1DJjTI6f6C',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: '[object Object]',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2021
        <i class="ri-heart-fill heart_icon"></i> panda
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/blog/"><img src="https://portrait.gitee.com/uploads/avatars/user/1007/3023420_bodboy_1578973210.png!avatar200" alt="小熊的博客"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags/%E6%97%85%E8%A1%8C/">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/blog/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/blog/js/jquery-2.0.3.min.js"></script>


<script src="/blog/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/blog/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/blog/dist/main.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>




<script src="/blog/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>

  
<script src="/blog/js/clickLove.js"></script>



<!-- 复制 -->



    
    <div id="music">
    
    
    
    <iframe frameborder="no" border="1" marginwidth="0" marginheight="0" width="200" height="52"
        src="//music.163.com/outchain/player?type=2&id=1297802566&auto=1&height=32"></iframe>
</div>

<style>
    #music {
        position: fixed;
        right: 15px;
        bottom: 0;
        z-index: 998;
    }
</style>
    
  </div>
</body>

</html>